<?php
$page_name=basename($_SERVER['SCRIPT_FILENAME']);
$IsPreserved	= 'Y';
$IsProcess		= $_REQUEST['IsProcess'];
include "general_include.php";
include "checklogin.php";
if($IsProcess <> 'Y')
{
	include "top.php";
	//include "left.php";
}

$item_per_page=$_SESSION['item_per_page'] = $_REQUEST['item_per_page'];
	if(empty($item_per_page) || !isset($item_per_page))
	{
	$item_per_page=10;
	} 

$action	= $_REQUEST['action'];

if($action=="del")
{	
	if(!empty($delete_id))
	{
		
		/*   $Reviewdtls = "SELECT * FROM ".TABLEPREFIX."_video_review WHERE video_review_id='$delete_id'";
		  $dtlsArr = $UserManagerObjAjax->GetRecords("Row",$Reviewdtls);
		  $rating = $dtlsArr['rating'];
		  $review_to_id = $dtlsArr['video_id'];
		  $is_active = $dtlsArr['is_active'];
		  $totreview = "SELECT count(*),sum(rating) as totrate FROM ".TABLEPREFIX."_video_review WHERE video_id='".$review_to_id."' AND is_active='Y'";
		  $totArr = $UserManagerObjAjax->GetRecords("Row",$totreview);
		  $tot_count = $totArr[0];
		  $tot_rate = $totArr['totrate'];
		  if($is_active == 'Y')
		  {
			$rate = $tot_rate-$rating;
			$totreviewer = $tot_count-1;
		  }	
		 $avg = round($rate/$totreviewer);
		  $UpdateSql = "UPDATE ".TABLEPREFIX."_video SET overall_rating='$avg' WHERE video_id='$review_to_id'";
		  $UserManagerObjAjax->Execute($UpdateSql);*/
		
		/* Delete review Starts */
		$SqlDelete="DELETE FROM ".TABLEPREFIX."_video_review WHERE video_review_id='$delete_id'";
		$UserManagerObjAjax->Execute($SqlDelete);		
		/* Delete review Ends */
	}	
		
}
// Start video Review By Me 
 $reviewvdo = "SELECT vr.*,v.video_title,v.video_image,u.name,u.user_id FROM ".TABLEPREFIX."_video_review vr,".TABLEPREFIX."_video v,".TABLEPREFIX."_user u WHERE 
 v.video_id=vr.video_id AND vr.reviewed_by='".$_SESSION['user_id']."' AND v.user_id=u.user_id ORDER BY vr.date_added DESC";
 $PaginationObjAjaxLatest=new PaginationClassAjax($item_per_page,"prev",'',"next","active",$adodbcon);
 $pagination_arr = $PaginationObjAjaxLatest->PaginationAjax($reviewvdo,$page_name."?action=".$action."&item_per_page=".$item_per_page,"Managergeneral");	
 $reviewvdoArr = $UserManagerObjAjax->GetRecords("All",$pagination_arr[0]);
 $Numvdoreview = count($reviewvdoArr);
 for($i=0;$i<$Numvdoreview;$i++)
 {
    $dateSql = "SELECT date_format('".$reviewvdoArr[$i]['date_added']."','%M  %d , %Y at %h:%i %p') as vdor_date";
	$DateArr = $UserManagerObjAjax->GetRecords("Row",$dateSql);
	$reviewvdoArr[$i]['review_date']=$DateArr['vdor_date'];

 }
// End video review By Me 
if($IsProcess == 'Y') {
	$Sqltype = "SELECT * FROM ".TABLEPREFIX."_user_type_user_relation WHERE user_id='".$_SESSION['user_id']."'";
	$typeArr = $UserManagerObjAjax->GetRecords("All",$Sqltype);
	$Numtype = count($typeArr);
	$is_coach = 0;
	$is_partner = 0;
	for($t=0;$t<$Numtype;$t++)
	{
	   if($typeArr[$t]['user_type_id']==1)
		  $is_coach = 1;
	   if($typeArr[$t]['user_type_id']==3)
		  $is_partner = 1;
	}
}	
$smarty->assign('is_coach',$is_coach);
$smarty->assign('is_partner',$is_partner);
$smarty->assign('Numvdoreview',$Numvdoreview);
$smarty->assign('reviewvdoArr',$reviewvdoArr);
$smarty->assign('page_name',$page_name);
$smarty->display('video_review.tpl');
if($IsProcess<>'Y')
  include "footer.php";
?>
